import {theme} from "../../model/theme";
import {Banner} from "../../model/Banner";
import {Category} from "../../model/Category";
import {Activty} from "../../model/Activty";
import {Spu} from "../../model/Spu";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        autoplay: true,
        indicatorDots: true,
        circular: true,
        interval: 5000,
        duration: 500,
        themeA: null,
        themeB: null,
        themeC: null,
        themeD: null,
        themeE: null,
        themeF: null,
        themeDDetail: {},
        themeEDetail: {},
        themeBDetail: {},
        activty: null,
        bannerA: [],
        bannerB: [],
        grid: Array,
        pagingObj:Object
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        const __this = this;
        __this.initAllData();
    },

    async initAllData(){
        const themeObj = new theme();
        themeObj.getThemeAll();
        const bannerA = await Banner.getBannerA();
        const bannerB = await Banner.getBannerB();
        const gridAll = await Category.getGridCategory();
        const activty = await Activty.getActivtyTheme();
        const themeB = themeObj.getThemeB();

        const themeE = themeObj.getThemeE();
        let themeBDetail = [];
        if (themeB.online) {
           let  themeDetail = await theme.getThemeBDetail();
            themeBDetail=(themeDetail.data.spu_list).slice(0,8);
        }

        const pagingObj = Spu.getPagingObj();
        let list = await pagingObj.getData();

        wx.lin.renderWaterFlow(list.data);

        this.setData({
            themeA: themeObj.getThemeA(),
            themeC: themeObj.getThemeC(),
            themeD: themeObj.getThemeD(),
            themeF: themeObj.getThemeF(),
            themeE: themeE,
            bannerA: bannerA.data,
            themeBDetail:themeBDetail,
            themeB:themeB,
            bannerB: bannerB.data,
            grid: gridAll.data,
            activty: activty.data
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})